var langData = langData || {};
//var defaultLan = ;
var defaultLan = localStorage.getItem('defaultLan') || 'en';

function lang(txt) {
	if(langData[defaultLan][txt]) {
		return langData[defaultLan][txt];
	}
	return txt;
}

function langInit() {
	var
		el = document.querySelectorAll('[lang]'),
		//el = document.querySelectorAll('*'),
		len = el.length,
		i = 0;
	//console.log(JSON.stringify(el));
	if(len > 0) {
		for(; i < len; i++) {
			var obj = el[i],
				inner = obj.innerText,
				title = obj.getAttribute('title'),
				placeholder = obj.getAttribute('placeholder'),
				titleLang = langData[defaultLan][title],
				placeholderLang = langData[defaultLan][placeholder],
				innerLang = langData[defaultLan][inner];
			//console.log(obj);
			if(inner && innerLang) {
				obj.innerText = innerLang;
			}
			if(title && titleLang) {
				obj.setAttribute('title', titleLang);
			}
			if(placeholder && placeholderLang) {
				obj.setAttribute('placeholder', placeholderLang);
			}

		}
	}
}
mui.ready(function() {
	langInit();
});